function setCookie(key, value, day) {
    if (day == undefined) { //会话级别
        document.cookie = `${key}=${value}`;
    } else { //长生命周期
        let date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = `${key}=${value};expires=` + date;;
    }
}

function getCookie(key) {
    let strCookie = document.cookie;
    let arrCookie = strCookie.split("; ");
    for (let i = 0; i < arrCookie.length; i++) {
        let item = arrCookie[i].split("=");
        if (key == item[0]) {
            return item[1];
        }
    }
    return '';
}

function delCookie(key) {
    setCookie(key, '', -1);
}